<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Employee.Master" Inherits="System.Web.Mvc.ViewPage<IndexViewModel>" %>
<%@ Import Namespace="System.Globalization"%>
<%@ Import Namespace="Website.Models.UserAdministration"%>
<%@ Import Namespace="PagedList"%>

<asp:Content ContentPlaceHolderID="TitleContent" runat="server">
	User Administration
</asp:Content>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">

	<link href='<% =Url.Content("~/Content/MvcMembership/MvcMembership.css") %>' rel="stylesheet" type="text/css" />

    <h2>User Administration</h2>
    <% =Html.ActionLink("Create User", "CreateUser", "UserAdministration") %>
     
    <h3>Users</h3>
    <div class="mvcMembership-allUsers">
    <% if(Model.Users.Count > 0){ %>
	<ul class="users">
    <table class="staffingexpert" style="width: 650px" cellspacing="0" id="JobsTable">
        <thead>
        <tr>
            <th>Username</th>
            <th>Email</th>
            <th>Status</th>
       </tr>
       </thead>
       <tbody>
       <% foreach(var user in Model.Users){ %>
           
             <tr>       
                <td style="width: 250px" align="center"><% =Html.ActionLink(user.UserName, "Details", new{ id = user.ProviderUserKey}) %></td>
                <td style="width: 250px" align="center"><a href="mailto:<% =Html.Encode(user.Email) %>"><% =Html.Encode(user.Email) %></a></td>
                 <% if(user.IsOnline){ %>
                  <td class="isOnline" style="width: 250px" align="center">Online</td>
					
				<% }else{ %>
					 <td class="isOffline" style="width: 250px" align="center">Offline for
						<%
							var offlineSince = (DateTime.Now - user.LastActivityDate);
							if (offlineSince.TotalSeconds <= 60) Response.Write("1 minute.");
							else if(offlineSince.TotalMinutes < 60) Response.Write(Math.Floor(offlineSince.TotalMinutes) + " minutes.");
							else if (offlineSince.TotalMinutes < 120) Response.Write("1 hour.");
							else if (offlineSince.TotalHours < 24) Response.Write(Math.Floor(offlineSince.TotalHours) + " hours.");
							else if (offlineSince.TotalHours < 48) Response.Write("1 day.");
							else Response.Write(Math.Floor(offlineSince.TotalDays) + " days.");
						%>
				<% } %>
                </td>
            </tr>      
        <% } %>
    </tbody>
    </table>
		<ul class="paging">
			<% if (Model.Users.IsFirstPage){ %>
			<li>First</li>
			<li>Previous</li>
			<% }else{ %>
			<li><% =Html.ActionLink("First", "Index") %></li>
			<li><% =Html.ActionLink("Previous", "Index", new { index = Model.Users.PageIndex - 1 })%></li>
			<% } %>

			<li>Page <% =Model.Users.PageNumber%> of <% =Model.Users.PageCount%></li>

			<% if (Model.Users.IsLastPage){ %>
			<li>Next</li>
			<li>Last</li>
			<% }else{ %>
			<li><% =Html.ActionLink("Next", "Index", new { index = Model.Users.PageIndex + 1 })%></li>
			<li><% =Html.ActionLink("Last", "Index", new { index = Model.Users.PageCount - 1 })%></li>
			<% } %>
		</ul>
	<% }else{ %>
		<p>No users have registered.</p>
	<% } %>
	</div>
</asp:Content>